<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>

<%@ page import ="com.easyattendance.services.AddClassService" %>
<%@ page import ="com.easyattendance.model.Class" %>
<%@ page import ="com.easyattendance.services.AddTeacherService" %>
<%@ page import ="com.easyattendance.model.Teacher" %>
<%@ page import ="com.easyattendance.model.ClassUser" %>
<html>
<head>
<title>Section -Class Settings</title>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" ></jsp:include>


<link rel="stylesheet" href="<%=request.getContextPath()%>/views/css/ui/jquery-ui-1.10.4.custom.min.css">
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.core.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.widget.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.accordion.js"></script>
<script>
	/* If want to fix height inner content of accordion - 
		remove 'heightStyle' line (and the above comma too :p ).
	*/
	$(function() {
		$( "#accordion" ).accordion({
			collapsible: true,
			heightStyle: "content",
		});
	});
</script>

</head>

<!--
		Note: Set the body element's class to "left-sidebar" to position the sidebar on the left.
		Set it to "right-sidebar" to, you guessed it, position it on the right.
	-->
<body class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp"></jsp:include>
<jsp:include page="../common/checkSectionRole.jsp" />

<% String currentUser = (String) session.getAttribute("currentUser"); %>
	<!-- Wrapper -->
	<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">


				<div>
					<form action="<%=request.getContextPath()%>/views/section/addClass.jsp">
						<input type="submit" value="Add Class" class="button add_button" tabindex="1">
					</form>
				</div>
				
				
				<span class="success_msg">${classUpdated}</span>
				<span class="error_msg">${classNotUpdated}</span>
				<span class="success_msg">${classDeleted}</span>
				<span class="error_msg">${classNotDeleted}</span>
				<span class="error_msg">${invalidChoice}</span>
				
				<div id="accordion" style="clear:both;">
				<% AddClassService addClassService = new AddClassService();	
					List<Class> ClassList = new ArrayList<Class>();
					ClassUser classUser = null;
					ClassList = addClassService.listClasses(currentUser);
					Class tempClass = null;
					int i=0;					
					Iterator ClassItr = ClassList.iterator();
					AddTeacherService addTeacherService = new AddTeacherService();	
					while(ClassItr.hasNext()) { i++;%>
						
						<h3> <% try {
									tempClass = (Class) ClassItr.next();
								} 
								catch(Exception ex){
									ex.printStackTrace();
								}%> 
								
								<%= tempClass.getClass_id() %>
								<% classUser = addClassService.getClassUserById(tempClass.getClass_id()); %>
						</h3>
						<div>
							<form name="class/deleteForm<%=i%>" action="${pageContext.request.contextPath}/AddClassServlet" action="post">
									<div>
										<input type="hidden" id="class_id<%=i%>" name="class_id<%=i%>" value="<%= tempClass.getClass_id() %>" >
										<input type="hidden" id="action_type" name="action_type" value="delete">
										<input type="hidden" id="i_value" name="i_value" value=<%=i%>>
										<input type="submit" value="" class="delete_button" alt="Delete" tabindex="1" onclick="return confirm('Are you sure?')">
									</div>
							</form>
						<div>
							<form name="classUpdateForm<%=i%>" action="${pageContext.request.contextPath}/AddClassServlet" action="post">
								<div>
									<input type="hidden" id="class_id<%=i%>" name="class_id<%=i%>" value="<%= tempClass.getClass_id() %>" >
									<input type="hidden" id="action_type" name="action_type" value="update">
									<input type="hidden" id="i_value" name="i_value" value=<%=i%>>
								</div>
																
								<!--  No of Electives  -->
								<div id="dataForm">
									<label>No of Electives:</label>
									<input type="number" id="class_elective_no<%=i%>" name="class_elective_no<%=i%>" min="0" value="<%=tempClass.getNo_of_electives()%>">
								</div>
								
								<!--  Common Student Id  -->
								<div id="dataForm">
									<label>Common Student Id:</label>
									<input type="text" id="common_student_id<%=i%>" name="common_student_id<%=i%>" value="<%=classUser.getEmail_id()%>">
								</div>
								
								<%-- <!--  Common Student password  -->
								<div id="dataForm">
									<label>Common Student Password:</label>
									<input type="text" id="common_student_pwd<%=i%>" name="common_student_pwd<%=i%>" value="<%=classUser.getPassword()%>" >
								</div> --%>
								
							    <div id="dataForm">
									<label>Class Teacher</label>
									<% String classTeacherName = addTeacherService.getTeacherById(tempClass.getClass_teacher_id()).getTeacher_name()+" "+addTeacherService.getTeacherById(tempClass.getClass_teacher_id()).getTeacher_lname(); %>
									<input type="text" id="class_teacher<%=i%>" name="class_teacher<%=i%>" value="<%=classTeacherName%>" readonly="readonly">
								</div> 
								
								<!--  Class Teacher -->
								<div id="dataForm">
								<label>Class Teacher Name:</label>
								<select tabindex="5" name="teacher_select<%=i%>" id="teacher_select"<%=i%>>
									<option value="">Choose Class Teacher To Change
									
										<% addTeacherService = new AddTeacherService();	
											List<Teacher> teacherList = new ArrayList<Teacher>();
											//get list of all teachers who are not already class teachers
											teacherList = addTeacherService.listNoneClassTeachers(currentUser);
											//teacherList = addTeacherService.listTeachers(currentUser);
											Teacher tempTeacher = null;
											Iterator<Teacher> teacherItr = teacherList.iterator();
									
											while(teacherItr.hasNext()) { %>
												<% tempTeacher = (Teacher) teacherItr.next();
													String teacherName = tempTeacher.getTeacher_name()+" "+tempTeacher.getTeacher_lname();
													String teacherId = tempTeacher.getTeacher_id(); %>
									<option value=<%=teacherId%>><%= teacherName %>
									<% } %>
								</select>
							</div>
								
								<!-- <div id="dataForm">
									<label>Password:</label>
									<input type="text" value="" >
								</div> -->
								<div>
									<%-- <input type="hidden" name="teacher_name"<%=i%> id="teacher_name"<%=i%> value=""> --%>
									<input type="submit" value="Update" class="button add_button" tabindex="6">									
								</div>
							</form>
						</div>
						</div>
					<% } %>
				</div>
				
			</div>
		</div>

		<!-- Sidebar -->
		<div id="sidebar">

			<!-- Sidebar Header - Logo & Name -->
			<jsp:include page="../common/sidebarHeader.jsp" ></jsp:include>

			<jsp:include page="sectionMenu.jsp" />
							
			<!-- Sidebar Footer Content -->
			<jsp:include page="../common/sidebarFooter.jsp" />

		</div>

	</div>
	<script type="text/javascript">
		$(function(){
			$("#classSettings").addClass("current_page_item");
		});
	</script>
	

</body>
</html>